package myLink;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2024/8/23-上午10:39
 * Since  :   1.0
 * Version:   1.0
 */
public class MyQueue {
    public int maxSize;
    public int rear;
    public int head;
    public Object array[];

    public MyQueue(int maxSize) {
        this.maxSize = maxSize;
        rear = -1;
        head = -1;
        array = new Object[maxSize];

    }

    public boolean isFull() {
        return rear == maxSize - 1;
    }

    public boolean isEmpty() {
        return head == rear;
    }

    public void addQueue(Object data) {
        if (isFull()) {
            System.out.println("Queue is full");
            return;
        }
        rear++;
        array[rear] = data;


    }

    public Object getQueue() throws Exception {
        if (isEmpty()) {
            System.out.println("Queue is empty");
           throw  new Exception("Queue is null,can not get data");
        }
        head++;
        return array[head];


    }

    public Object showHeadData(){
        return array[head+1];
    }




}
